/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package save;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import mobile.Call;
import mobile.Message;
import mobile.MobileConsumption;
import plan.Plan;
import turnover.Consumption;

/**
 *
 * @author Ale
 */
public class Orange_modulo_fijos_24h extends Save {


    @Override
    public Consumption applySave(Consumption consumption) {
        int totalCallsFixedLine = 0;
        MobileConsumption mc = (MobileConsumption) consumption;
        MobileConsumption ret = new MobileConsumption(mc.getIdCons(), mc.getAmount(), mc.getNumCalls(), mc.getNumMess(), mc.getConsCalls(), mc.getFrom(), mc.getTo());
        List callList = new LinkedList();
        Iterator itCall = mc.getCallList().iterator();
        while (itCall.hasNext()){
            Call c = (Call)itCall.next();
            try {
                callList.add(c.clone());
            } catch (CloneNotSupportedException ex) {
                Logger.getLogger(Orange_Bono_ahorroSMS.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        ret.setCallList(callList);


        List messList = new LinkedList();
        Iterator itMess = mc.getMessList().iterator();
        while (itMess.hasNext()){
            Message m = (Message)itMess.next();
            try {
                messList.add(m.clone());
            } catch (CloneNotSupportedException ex) {
                Logger.getLogger(Orange_Bono_ahorroSMS.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        ret.setMessList(messList);

        Iterator it = ret.getCallList().iterator();
        ret.setAmount(9);
        while (it.hasNext()) {
            Call c = (Call) it.next();
            if (c.isFixedLineTelephone()) {
                it.remove();
                totalCallsFixedLine++;
            }
        }
        return ret;
    }

    public Orange_modulo_fijos_24h (Plan plan) {
        super(plan);
        super.setName("Orange modulo fijos 24h");
        super.getSavesNoCompatibles().add("Bono Prueba");
    }



    @Override
    public double getCost(Consumption consumption){
        double total = 0d;
        Consumption con = this.applySave(consumption);
        total = super.getPlan().getCost(con);
        return total;
    }

}
